package hotel.action;

import hotel.model.IRequest;
import hotel.model.IRoom;
import hotel.service.RequestService;
import hotel.service.RoomService;
import hotel.service.ServiceManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class StrongAcceptRequestAction extends Action 
{
	private static final Logger logger = Logger.getLogger(StrongAcceptRequestAction.class);
	private static final String STRONGACCEPTREQUESTACTION_ERROR = "Error in StrongAcceptRequestAction:";
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest httpRequest, HttpServletResponse response)
		    throws Exception 
	{
		String mapper = ForwardActionTo.ERROR;
		try
		{
			IRequest request = null;
			IRoom room = null;
			int rid = 0;
			int reid = 0;
					
			RequestService requestService = ServiceManager.getDefault().getRequestService();
			RoomService roomService = ServiceManager.getDefault().getRoomService();
		
			rid = Integer.valueOf(httpRequest.getParameter("rid"));
			reid = Integer.valueOf(httpRequest.getParameter("reid"));
			request = requestService.getById(reid);
			room = roomService.getById(rid);
			
			try
			{
				roomService.updateRoom(room.getId(), request.getId());
			}
			catch(Exception e) 
			{
				
			}
			finally
			{
				mapper = ForwardActionTo.SUCCESS;
			}
			requestService.deleteRequest(reid);
		}
		catch(NullPointerException e)
		{
			logger.error(STRONGACCEPTREQUESTACTION_ERROR + e);
		}
		
		return mapping.findForward(mapper);
	}

}
